<!DOCTYPE html>
<html lang="zh-cn">
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <title>Generator 函数的含义与用法</title>
    </head>
    <body>
        <h1>Generator 函数的含义与用法</h1>
        <p>来源:<a href="http://www.ruanyifeng.com/blog/2015/04/generator.html">http://www.ruanyifeng.com/blog/2015/04/generator.html</a></p>
        <script>
            var fetch = require('node-fetch');

            function* gen(){
              var url = 'https://api.github.com/users/github';
              var result = yield fetch(url);
              console.log(result.bio);
            }

            var g = gen();
            var result = g.next();

            result.value.then(function(data){
              return data.json();
            }).then(function(data){
              g.next(data);
            });
        </script>
    </body>
</html>